//
//  ShouyeViewController.m
//  诗韵
//
//  Created by Song on 2018/3/6.
//  Copyright © 2018年 Song. All rights reserved.
//

#import "ShouyeViewController.h"
#import "messageView.h"

#import "raceViewController.h"
#import "meetingViewController.h"
#import "bookStoreViewController.h"
#import "homeworkViewController.h"

@interface ShouyeViewController ()

@property(nonatomic,weak) messageView *mview;

- (IBAction)race:(id)sender; // 赛事进程
- (IBAction)meeting:(id)sender; // 诗词大会
- (IBAction)bookStore:(id)sender; // 藏书阁
- (IBAction)homework:(id)sender; // 今日作业



@end

@implementation ShouyeViewController

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    self.view.frame = [UIScreen mainScreen].bounds;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
//    NSLog(@" = %lf",self.view.frame.size.width);
//    NSLog(@" = %lf",self.view.frame.size.height);
    
    [self setupNav];
    [self messageView1];
    
    self.view.backgroundColor = [UIColor redColor];
    
    

}

// 设置导航栏
-(void)setupNav {
    
    UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 280, 25)];
//    text.backgroundColor = [UIColor redColor];
    text.background = [UIImage imageNamed:@"input"];
    text.placeholder = @" 请输入关键字进行搜索";
    [text setFont:[UIFont systemFontOfSize:14]];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:text];
    
    UIButton *rightbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightbtn setImage:[UIImage imageNamed:@"xiaoxi"] forState:UIControlStateNormal];
    [rightbtn addTarget:self action:@selector(messageClick) forControlEvents:UIControlEventTouchUpInside];
    [rightbtn sizeToFit];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightbtn];
}

// 信封点击后出现的界面
-(void)messageView1 {
    NSLog(@"messageView");
    
    messageView *mView = [[messageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
    
    NSLog(@"%@",NSStringFromCGRect(self.view.frame));

    self.mview = mView;
    [self.tabBarController.view addSubview:mView];

 
}

// 信封点击后出现的界面de动画
-(void)messageClick {
    
    [UIView animateWithDuration:0.3 animations:^{
        self.mview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    }];
    
    self.mview.leftView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mviewClick:)];
    [self.mview.leftView addGestureRecognizer:tap];

}

// mview点击后收回
-(void)mviewClick:(UITapGestureRecognizer *)gesture {
    NSLog(@"leftView - click");
    [UIView animateWithDuration:1.0 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.8 options:UIViewAnimationOptionCurveEaseOut  animations:^{
        
        self.mview.frame = CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
        
    } completion:nil];
}

//-(void)viewWillDisappear:(BOOL)animated {
//    [super viewWillDisappear:animated];
//    self.tabBarController.tabBar.hidden = YES;
//}

- (IBAction)race:(id)sender {
    NSLog(@"赛事进程");
    raceViewController *raceView = [[raceViewController alloc] init];
    [self presentViewController:raceView animated:YES completion:nil];
}
- (IBAction)meeting:(id)sender {
    NSLog(@"诗词大会");
    meetingViewController *meetingView = [[meetingViewController alloc] init];
    [self presentViewController:meetingView animated:YES completion:nil];
}
- (IBAction)bookStore:(id)sender {
    NSLog(@"藏书阁");
    bookStoreViewController *bookView = [[bookStoreViewController alloc] init];
    [self presentViewController:bookView animated:YES completion:nil];
}
- (IBAction)homework:(id)sender {
    NSLog(@"今日作业");
    homeworkViewController *homeworkView = [[homeworkViewController alloc] init];
    [self presentViewController:homeworkView animated:YES completion:nil];
}
@end
